const { defineConfig } = require('@vue/cli-service')
const TerserPlugin = require("terser-webpack-plugin");
module.exports = defineConfig({
  transpileDependencies: true,
  // electron-builder配置
  // pluginOptions: {
  //   electronBuilder: {
  //     builderOptions: {
  //       // 额外资源配置
  //       extraFiles: ["./conf"],
  //     },
  //   },
  // },
  lintOnSave: false,
  productionSourceMap: false,
  publicPath: './',
  devServer: {
    proxy: {
      '/api': {
        // target: "http://192.168.30.144:8125/", // node-server 外网
        // target: "http://10.194.228.59:8125/", // node-server 内网
        target: "http://139.9.136.42:8125/", // node-server 服务器
        changeOrigin: true,
        logLevel: 'debug',
        ws: true,
        pathRewrite: {
          '^/api': '/',
        },
      },
      '/static': {
        target: "https://cdn.utonmos.com", //测试1
        changeOrigin: true,
        logLevel: 'debug',
        ws: true,
        pathRewrite: {
          '^/static': '/static',
        },
      },
    },
  },
  css: {
    loaderOptions: {
      sass: {
        // additionalData: `@import "./src/assets/styles/common";`,
      },
    },
  },
  configureWebpack: config => {
    config.resolve.alias = {
      ...config.resolve.alias,
      'vue$': 'vue/dist/vue.esm.js'
    }
    // 重要!! 配置 操作node fs模块
    // 为Electron启动添加Node相关配置
    // config.target = 'electron-renderer';
    // config.externals = {
    //   fs: 'commonjs fs'
    // };
    // console.log(process.env.IS_ELECTRON,'process.env.IS_ELECTRON')
    if (process.env.NODE_ENV != 'development') {
      config.optimization = {
        minimize: true,
        nodeEnv: false,
        minimizer: [new TerserPlugin({
          terserOptions: {
            ecma: undefined,
            warnings: false,
            parse: {},
            compress: {
              drop_console: true,
              drop_debugger: true,
              pure_funcs: ['console.log'],//移除console
            }
          }
        })]
      }
    } else {
      // 为开发环境修改配置...
    }
  }
})
